package com.focusai.efairy.ui.widget;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.focusai.efairy.R;

/**
 * Created by luo_guangwen on 2017/10/10.
 */

public class PopWindowDevChatTipView extends PopupWindow {
    private Context mContext;
    private TextView textTip;

    public PopWindowDevChatTipView(Context context) {
        super(context);
        this.mContext = context;
        init();
    }

    private void init() {
        View contentView = LayoutInflater.from(mContext).inflate(R.layout.view_pop_chat_tip, null);
        this.setContentView(contentView);
        this.setOutsideTouchable(false);
        this.setFocusable(false);
        this.setTouchable(false);
        //设置PopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置PopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
//        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(mContext.getResources().getColor(R.color.transparent));
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        //设置SelectPicPopupWindow弹出窗体动画效果
//        this.setAnimationStyle(R.style.popup_window_from_top);
        textTip = (TextView) contentView.findViewById(R.id.text_tip);
        textTip.setText(mContext.getResources().getString(R.string.unhandle_device_tip,"0"));
    }

    public void show(View view,int count) {
        dismiss();
//        showAtLocation(view, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        textTip.setText(mContext.getResources().getString(R.string.unhandle_device_tip,count+""));
        if(mContext != null && view != null){
            showAsDropDown(view,0,0);
        }
    }

    @Override
    public void dismiss() {
        if (this.isShowing()) {
            super.dismiss();
        }
    }
}
